using System;
using System.Collections;
using System.Data;
using CE.Database;
/// <summary>
/// Summary description for UserProfileDB
/// </summary>
/// 
namespace CE.Company
{
    public class CompanyInformationDB
    {
        public CompanyInformationDB()
        {
            //
            // TODO: Add constructor logic here
            //
        }

        public Int64 Insert(CompanyInformation company)
        {
            MyDatabase _db = new MyDatabase();
            Int64 _result = -1;
            string _spName = "[sprocTemplateInsertUpdateSingleItem]";

            SortedList _sPara = new SortedList();

            #region Parameter
            _sPara.Add("@Status", company.Status);
            _sPara.Add("@Info1", company.Info1);
            _sPara.Add("@Info2", company.Info2);
            _sPara.Add("@Info3", company.Info3);
            _sPara.Add("@Info4", company.Info4);
            _sPara.Add("@Info5", company.Info5);
            _sPara.Add("@NInfo1", company.NInfo1);
            _sPara.Add("@NInfo2", company.NInfo2);
            _sPara.Add("@FInfo1", company.FInfo1);
            _sPara.Add("@FInfo2", company.FInfo2);
            _sPara.Add("@DInfo1", company.DInfo1);
            #endregion

            _result = _db.ExecuteSP(_spName, _sPara);

            return _result;
        }

        public CompanyInformation GetCompanyInformation(int CompanyId)
        {
            CompanyInformation _company = null;
            MyDatabase _db = new MyDatabase();
            string _spName = "sprocCompanyInformationSelectSingleItem";

            SortedList _spara = new SortedList();
            _spara.Add("@CompanyId", CompanyId);

            using (DataTable _dt = _db.GetDataTableBySP(_spName, _spara))
            {
                if (_dt != null && _dt.Rows.Count > 0)
                {
                    _company = new CompanyInformation();
                    _company = FillDataRecord(_dt, 0);
                }
            }
            return _company;
        }


        public bool Update()
        {
            return true;
        }

        public bool Delete()
        {
            return true;
        }

        private CompanyInformation FillDataRecord(DataTable myDataTable, int RowId)
        {
            CompanyInformation myCompany = new CompanyInformation();
            myCompany.CompanyId = Convert.ToInt32(myDataTable.Rows[RowId]["CompanyId"].ToString());
            myCompany.CompanyName = myDataTable.Rows[RowId]["CompanyName"].ToString();
            myCompany.CompanyLogoUrl = myDataTable.Rows[RowId]["CompanyLogoUrl"].ToString();
            myCompany.CompanyRegistrationNo = myDataTable.Rows[RowId]["CompanyRegistrationNo"].ToString();
            myCompany.CompanyDescription = myDataTable.Rows[RowId]["CompanyDescription"].ToString();
            myCompany.Address1 = myDataTable.Rows[RowId]["Address1"].ToString();
            myCompany.Address2 = myDataTable.Rows[RowId]["Address2"].ToString();
            myCompany.Telephone = myDataTable.Rows[RowId]["Telephone"].ToString();
            myCompany.FaxNo = myDataTable.Rows[RowId]["FaxNo"].ToString();
            myCompany.EmailAddress = myDataTable.Rows[RowId]["EmailAddress"].ToString();
            myCompany.Website = myDataTable.Rows[RowId]["Website"].ToString();
            myCompany.PostCode = myDataTable.Rows[RowId]["PostCode"].ToString();
            myCompany.Country = myDataTable.Rows[RowId]["Country"].ToString();
            myCompany.Status = Convert.ToBoolean(myDataTable.Rows[RowId]["Status"].ToString());
            return myCompany;
        }

    }
}